<template>
	<view class="content">
<!-- 		<uni-forms
			ref="form"
			:model="formData"
			label-position="top"
		>
			<uni-forms-item name="nick" label="昵称">
				<uni-easyinput v-model="formData.nick" type="text" placeholder="昵称" />
			</uni-forms-item>
			<uni-forms-item name="uImg" label="头像">
				<uni-easyinput v-model="formData.nick" type="text" placeholder="头像" />
			</uni-forms-item>
			<view class="form-item submit">
				<button type="default" @tap="submit">登录</button>
			</view>
		</uni-forms> -->
		<button open-type="getUserInfo" @getuserinfo="getUserInfo">请登录</button>
		<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">请登录</button>
	</view>
</template>

<script>
import { nextTick } from 'vue'
import { getProvider, navigateBack, showModal, showToast, uniLogin } from '../../utils/promise'

	export default {
		data() {
			return {
				formData: {
					nick: "",
					uImg: "",
				}
			}
		},
		onShow() {
			
		},
		onLoad() {
			const userInfo = uni.getStorageSync("userInfo")
			if(Object.keys(userInfo).length === 0) {
				this.grantLogin()
				return
			}
		},
		methods: {
			grantLogin() {
				showModal({
					title: "授权确认",
					content: "是否授权微信登录",
					showCancel: true,
					cancelText: "否",
					confirmText: "是",
				}).then((res) => {
					// console.log(res)
					const {confirm, cancel} = res.res
					if(cancel) {
						navigateBack()
						return
					}
					// console.log(confirm, cancel)
					this.wxLogin()
				}).catch((err) => {
					console.log(err)
				})
			},
			async wxLogin() {
				let provider, code
				await getProvider({
					service: "oauth"
				}).then((res) => {
					// console.log(res)
					provider = res.res.provider[0]
				})
				await uniLogin({
					provider: provider,
				}).then((res) => {
					// console.log(provider)
					// console.log(res)
					code = res.res.code
				})
				// console.log(code)
			},
			getUserInfo(e) {
				console.log(e)
			},
			getPhoneNumber(e) {
				console.log(e)
			},
		}
	}
</script>

<style>
.content {
	width: 90vw;
	margin: 0 auto;
}
.submit {
	background-color: transparent;
	padding: 100rpx 0;
	width: 80%;
	position: absolute;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	place-content: center;
	place-items: center;
}
.submit button {
	padding: 10rpx 0;
	background-color: rgb(15, 76, 151);
	color: white;
	border-radius: 60rpx;
	width: 100%;
}
</style>
